<?php 

namespace plugins\fund\common;

use plugins\pay\lib\Pay;
use plugins\fund\model\FundModel;
use plugins\fund\common\Request;
use plugins\pay\lib\Common as LCOM;

class Common
{
	/**
     * 创建支付
     */
    public function createPay( $payType , $bizcontent )
    {
        $instance = Pay::createInstance( $payType );
        $bizcontent = json_encode($bizcontent, JSON_UNESCAPED_UNICODE);
        $res = $instance->expense($bizcontent);
        return $res;
    }

    /**
     * 提现
     */
    public function createTx( $payType , $bizcontent )
    {
        $instance = Pay::createInstance( $payType );
        $bizcontent = json_encode($bizcontent, JSON_UNESCAPED_UNICODE);
        $res = $instance->earning($bizcontent);
        return $res;
    }

    /**
     * 获取开启的支付列表
     */
    public static function getPayList()
    {
        $list = LCOM::getPayListWithOn();//已开启的
        $config = [];
        foreach ( $list as $v ){
            try {
                $obj = Pay::createInstance( strtolower( $v ) );
            } catch ( \Exception $e) {
                continue;
            }
            if( in_array( $obj->getPayType() , $list ) ){
                $con = $obj->getConfig();
                $config [] = [
                    'icon' => zy_domain().$con[ 'icon' ],
                    'type' => $obj->getPayType(),
                    'name' => $obj->name,
                ];
            }
        }
        return $config;
    }


}

